package middleware

import (
	"errors"
	//"gitee.com/gopher2011/go-zero-gva/internal/logic/other"

	"gitee.com/gopher2011/go-zero-gva/internal/types"
	"github.com/tal-tech/go-zero/rest/httpx"
	"net/http"
)

var (
	TokenExpired     = errors.New("Token is expired")
	TokenNotValidYet = errors.New("Token not active yet")
	TokenMalformed   = errors.New("That's not even a token")
	TokenInvalid     = errors.New("Couldn't handle this token:")
)
type H map[string]interface{}

type JwtAuth struct {}

func NewJwtAuth() *JwtAuth {
	return &JwtAuth{}
}

func (m *JwtAuth) Handle(next http.HandlerFunc) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		// 每个请求的请求头 必须带有 x-token 这个 key 并且它必须有 token 值
		token := r.Header.Get("x-token")
		if token == "" {
			httpx.OkJson(w,&types.Response{
				Code: 7,
				Msg: "未登录或非法访问",
				Data: H{
					"reload": true,
				},
			})
		}
		next(w, r)
	}
}





